
package com.funo.government.info.components;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.text.TextUtils;

import com.funo.government.info.utils.LogUtils;

public class PullService extends Service {

    private static final int INTERVAL = 300000;

    private static final String TAG = "PullService";

    PendingIntent operation;

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {

        LogUtils.d(TAG, "service create");
        AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
        Intent dest = new Intent(this, QueryMessageReceiver.class);
        operation = PendingIntent.getBroadcast(this, 0, dest, PendingIntent.FLAG_UPDATE_CURRENT);
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), INTERVAL,
                operation);
        super.onCreate();
    }

    @Override
    public void onDestroy() {
        LogUtils.d(TAG, "onDestroy");
        AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
        if (operation != null) {
            alarmManager.cancel(operation);
        }
        super.onDestroy();
    }
}
